package com.xbongbong.saas.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 业务评论
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/26 21:47
 * @since v1.0
 */
@Getter
public enum BusinessCommentEnum {
    /**
     * 业务评论
     */
    APPROVAL(1,XbbRefTypeEnum.APPROVAL.getCode(),"",""),
    CONTRACT(2,XbbRefTypeEnum.CONTRACT.getCode(),"",""),
    OPPORTUNITY(3,XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(),"",""),
    CUSTOMER_COMMUNICATE(4,XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(),"",""),
    SUPPLIER_COMMUNICATE(5,XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(),"",""),
    WORK_REPORT(6,XbbRefTypeEnum.WORK_REPORT.getCode(),"",""),
    WORK_ORDER(7,XbbRefTypeEnum.WORK_ORDER.getCode(),"",""),
    CUSTOMER_STAGE(8,XbbRefTypeEnum.CUSTOMER_STAGE.getCode(),"",""),
    SALE_STAGE(9,XbbRefTypeEnum.SALE_STAGE.getCode(),"",""),
    CLUE_STAGE(10,XbbRefTypeEnum.CLUE_STAGE.getCode(),"",""),
    DISTRIBUTOR_COMMUNICATE(11,XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(),"",""),
    PAAS_STAGE(12,0,"",""),
    WORK_ORDER_V2(13,XbbRefTypeEnum.WORK_ORDER_V2.getCode(),"",""),
    CONTRACT_STAGE(14, XbbRefTypeEnum.CONTRACT_STAGE.getCode(),"",""),
    COMMENT_REPLY(15,1,"",""),
    ;
    private Integer code;
    private Integer businessType;
    private String attr;
    private String alias;

    BusinessCommentEnum(Integer code, Integer businessType, String attr, String alias) {
        this.code = code;
        this.businessType = businessType;
        this.attr = attr;
        this.alias = alias;
    }

    public static BusinessCommentEnum getByBusinessType(Integer businessType){
        for (BusinessCommentEnum businessCommentEnum : values()){
            if (Objects.equals(businessCommentEnum.getBusinessType(),businessType)){
                return businessCommentEnum;
            }
        }
        return null;
    }

    /**
     * 是否是阶段推进器的评论
     * @param businessType
     * @return
     */
    public static boolean isStage(Integer businessType){
        List<BusinessCommentEnum> stageList = Arrays.asList(CUSTOMER_STAGE, CLUE_STAGE, SALE_STAGE, PAAS_STAGE);
        BusinessCommentEnum businessCommentEnum = getByBusinessType(businessType);
        return stageList.contains(businessCommentEnum);
    }
}
